using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class ZB_ExamUserService : BaseAppService<ZB_ExamUserDto, ZB_ExamUser , ZB_ExamUserRepository>
        {
        readonly ExcelHelp _excelHelp;
        public ZB_ExamUserService (ZB_ExamUserRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<ZB_ExamUser, ZB_ExamUserDto>
            GetLoadPageOffsetMode(PagingModel<ZB_ExamUserDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("Type","=") //
         .Add("ZBCourseId","=") //
         .Add("ZBTrainPlanId","=") //
         .Add("PersonID","=") //
         .Add("Fullmarks","=") //
         .Add("Qualificationscore","=") //
         .Add("Answerscore","=") //
         .Add("IsQualified","=") //
         .Add("Examinationstatus","=") //
         .Add("Numberofexaminations","=") //
         .Add("CreateFactory","=") //
         .Add("CreateDept","=") //
         .Add("UpdateDept","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  ZB_ExamUser() {
                Id = model.Id,
Type= model.Type,//
ZBCourseId= model.ZBCourseId,//
ZBTrainPlanId= model.ZBTrainPlanId,//
PersonID= model.PersonID,//
Fullmarks= model.Fullmarks,//
Qualificationscore= model.Qualificationscore,//
Answerscore= model.Answerscore,//
IsQualified= model.IsQualified,//
Examinationstatus= model.Examinationstatus,//
Numberofexaminations= model.Numberofexaminations,//
CreateFactory= model.CreateFactory,//
CreateDept= model.CreateDept,//
UpdateDept= model.UpdateDept,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<ZB_ExamUserDto>> GetList(PagingModel<ZB_ExamUserDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<ZB_ExamUserDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.Type,
Type_title ="",
model.ZBCourseId,
ZBCourseId_title ="",
model.ZBTrainPlanId,
ZBTrainPlanId_title ="",
model.PersonID,
PersonID_title ="",
model.Fullmarks,
Fullmarks_title ="",
model.Qualificationscore,
Qualificationscore_title ="",
model.Answerscore,
Answerscore_title ="",
model.IsQualified,
IsQualified_title ="",
model.Examinationstatus,
Examinationstatus_title ="",
model.Numberofexaminations,
Numberofexaminations_title ="",
model.CreateFactory,
CreateFactory_title ="",
model.CreateDept,
CreateDept_title ="",
model.UpdateDept,
UpdateDept_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
